import Home from '@/views/Menu-page.vue'
import Login from '@/views/Login.vue'
import store from '@/store'
import getToken from '@/lib/util.js'

export const routerMap = [
  {
    path: '/',
    name: 'home',
    meta: {
      title: '首页'
    },
    children: [
      {
        path: 'folder-tree',
        name: 'folder_tree',
        meta: {
          title: '文件夹'
        },
        component: () => import('@/views/FolderTree')
      }
    ],
    component: Home
  },
  {
    path: '/optimize',
    name: 'optimize',
    meta: {
      title: '大数据性能优化'
    },
    component: () => import('@/views/optimize')
  }
]

export const routes = [
  {
    path: '/login',
    name: 'login',
    meta: {
      title: '登录'
    },
    component: Login
  },
  {
    path: '*',
    component: () => import('@/views/404.vue')
  }
]

// router.beforeEach((to, from, next) => {
//   router.addRoutes(routerMap)
//   console.log(router.options.routes)
//   next({ ...to, replace: true })
// })
// router.beforeEach((to, from, next) => {
//   router.options.routes = routerMap
//   console.log(router.options.routes)
//   next({ replace: true })
// })
// router.beforeEach((to, from, next) => {
//   // const token = getToken()
//   if (true) {
//     if (!store.state.router.hasGetRules) {
//       store.dispatch('authorization').then(rules => {
//         store.dispatch('concatRoutes', rules).then((routers) => {
//           console.log(store.state.router.routers)
//           // console.log(router)
//           router.addRoutes(store.state.router.routers)
//           next({ ...to, replace: true })
//         }).catch(() => {
//           next({ name: 'login' })
//         })
//       })
//     }
//     else next()
//   }
//   else {
//     if (to.name === 'login') next()
//     else next({name: 'login'})
//   }
// })
